
import json
from SpiderUtil import *


#获得代理IP
def GetProxyIPs(proxyUrl):
    try:
        if proxyUrl == None:
            return None;
        Resp = HtmlGet(proxyUrl);
         # print("GetProxyIPs Resp.status_code=", Resp.status_code);
        print("Resp.text=", Resp.text);
        #返回成功
        if Resp.status_code==200:
            #解析Json
            RJson = json.loads(Resp.text);
            if RJson['success']==True:
                return RJson['data'];
    except Exception as e:
        print("get proxy ip except info:", e)
    #Resp失败
    return None;

#生成Selinum使用的代理信息
def PorxyInfo(proxyUrl):
    #获得代理IP列表
    ProxyList = GetProxyIPs(proxyUrl);
    if ProxyList==None or len(ProxyList)==0:
        # print("len(ProxyList)==0 !!!!!!");
        return None;

    ProxyInfo = {
        "IP": ProxyList[0]["ip"], 
        "PORT": ProxyList[0]["port"],
    };
    return ProxyInfo;
    #end

#测试代码
if __name__ == "__main__":

    #实例化
    print("proxy>>>>>>>>>>>>")

    #end